import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
  constructor(private route: ActivatedRoute, private router: Router) {}

  ngOnInit() {
    this.route.queryParams.subscribe(params => {
      // 获取参数后跳转
      if(params['id']) {
        this.router.navigate(['detail', params['id']], {
          queryParamsHandling: 'preserve' // 保留现有查询参数
        });
      }
    });
  }
}
